<div class="on_cancel fieldset">
    <%
       task = scope[:task]
    %>
    <%- if (task.hasCancelTask() && (task.cancelTask().instance_of? com.thoughtworks.go.config.pluggabletask.PluggableTask) && !scope[:config_store].preferenceFor(task.cancelTask().getPluginConfiguration().getId())) %>
        <div class="flash" id="plugin_missing_error">
            <p class="warning">On Cancel task is not available because associated plugin '<%= task.cancelTask().getPluginConfiguration().getId() %>' is missing. Please contact Go admin to verify or re-install plugin. Click on 'Save' will replace the current On Cancel task.</p>
        </div>
    <%- end %>

    <%= scope[:form].check_box(com.thoughtworks.go.config.AbstractTask::HAS_CANCEL_TASK, :class => "has_cancel_task", :id => "has_cancel_task") -%>
    <%= label_tag :has_cancel_task, 'On Cancel Task', :class => "inline" -%>
    <div class="on_cancel_task <%= task.hasCancelTask() ? '' : 'hidden' %>">
        <%= scope[:form].fields_for com.thoughtworks.go.config.AbstractTask::ON_CANCEL_CONFIG, task.onCancelConfig do |on_cancel_config| %>
            <%= on_cancel_config.select(com.thoughtworks.go.config.OnCancelConfig::ON_CANCEL_OPTIONS, task_options, {:selected => selected_option(task.onCancelConfig())}, {:class => "on_cancel_type", :id => "on_cancel_task_options"}) %>
            <% tasks = com.thoughtworks.go.config.Tasks.new() %>
            <% @on_cancel_task_vms.each do |oncancel_task_vm|
                oncancel_task = oncancel_task_vm.getModel()
                task_class_name = oncancel_task.getTaskType()
                next if task_class_name == "fetch"
            %>
                <div class="hidden task_entry <%= task_class_name -%>">
                    <%= on_cancel_config.fields_for oncancel_task.getTaskType() + "OnCancel", oncancel_task do |task_form| %>
                        <%== render_pluggable_form_template(oncancel_task_vm, form_name_provider(task_form), {:scope => {:form => task_form, :task => oncancel_task}}) -%>
                    <% end %>
                </div>
            <% end %>
        <% end %>
    </div>
</div>

<script type="text/javascript">
    Util.on_load(function() {
        var helper = new TaskEditor.TypeEditor({container: jQuery('.on_cancel_task'), switch_control: jQuery('.on_cancel_type'), entry_to_be_hidden: '.task_entry'});
        helper.showHideCheckbox(jQuery('.has_cancel_task'));//memory leak
        if(<%= @is_config_repo_pipeline || false %>) {
            Util.disableAllFormElementsFor('.on_cancel');
        }
    });
</script>
